package com.ryskoo.basicdata.area.region.repository;

import com.ryskoo.basicdata.area.region.domain.RegionPO;
import com.ryskoo.framework.core.bean.QueryConditionEnum;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author qyc
 */
@Repository
public class RegionJPAImpl extends BasicJPAImpl<RegionPO> implements IRegionRepository {

	@Override
	public List<RegionPO> getRegionsByCityId(String cityId) {
		QueryMessageDTO qm = new QueryMessageDTO();
		qm.addCondition("parentId", QueryConditionEnum.EQ.name(), cityId);
		List<RegionPO> list = this.queryByCondition(qm, false);
		return list;
	}

	@Override
	public RegionPO getByEntityNo(String entityNo) {
		String hql = "select o from RegionPO o where o.entityNo = :entityNo ";
		Query query = getH4Session().createQuery(hql);
		query.setString("entityNo",entityNo);
		return (RegionPO)query.uniqueResult();
	}
}
